package com.denlaku.longan.controller.impl;

import com.denlaku.longan.controller.MyFavorController;
import com.denlaku.longan.core.Current;
import com.denlaku.longan.http.Resp;
import com.denlaku.longan.http.Return;
import com.denlaku.longan.qo.MyFavorQuery;
import com.denlaku.longan.service.MyFavorService;
import com.denlaku.longan.vo.MyFavor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author tianx
 */
@RestController
public class MyFavorControllerImpl implements MyFavorController {
    @Autowired
    private MyFavorService myFavorService;

    @Override
    public Return<Long> add(@RequestBody MyFavor myCollect) {
        myFavorService.add(myCollect);
        return Resp.success(myCollect.getId());
    }

    @Override
    public Return<Void> delete(Long id) {
        myFavorService.delete(id);
        return Resp.success();
    }

    @Override
    public Return<Void> clear() {
        Long userId = Current.getUserId();
        myFavorService.deleteByUid(userId);
        return Resp.success();
    }

    @Override
    public Return<List<MyFavor>> list(@RequestBody MyFavorQuery query) {
        Long userId = Current.getUserId();
        query.setUserId(userId);
        List<MyFavor> list = myFavorService.list(query);
        return Resp.success(list);
    }
}
